<script setup lang="ts">
defineProps<{
  options: { lable: string; value: number }[];
  modelValue?: string | number;
}>();
// const emit = defineEmits<{ (e: "updata:modelValue", data: number): void }>();
const emit = defineEmits<{
  (e: "update:modelValue", value: string | number): void;
}>();
const toggleItem = (value: number) => {
  // 触发自定义事件把数据给父组件
  console.log(value);
  emit("update:modelValue", value);
};
</script>

<template>
  <div class="cp-radio-btn">
    <a
      class="item"
      :class="{ active: modelValue === itme.value }"
      @click="emit('update:modelValue', itme.value)"
      v-for="(itme, index) in options"
      :key="index"
      href="javascript:;"
      >{{ itme.lable }}</a
    >
  </div>
</template>

<style lang="scss" scoped>
.cp-radio-btn {
  display: flex;
  flex-wrap: wrap;
  .item {
    height: 32px;
    min-width: 70px;
    line-height: 30px;
    padding: 0 14px;
    text-align: center;
    border: 1px solid var(--cp-bg);
    background-color: var(--cp-bg);
    margin-right: 10px;
    box-sizing: border-box;
    color: var(--cp-text2);
    margin-bottom: 10px;
    border-radius: 4px;
    transition: all 0.3s;
    &.active {
      border-color: var(--cp-primary);
      background-color: var(--cp-plain);
    }
  }
}
</style>